package com.pet.system.domain.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pet.system.domain.entity.SysUser;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统-用户 DTO 模型
 *
 * @author Centaurea
 */
@ToString
public class SysUserDTO extends SysUser {
  /** 向外输出时，忽略 password、salt */
  @JsonIgnore private String password;
  /** 向外输出时，忽略 password、salt */
  @JsonIgnore private String salt;

  /** 逗号分隔的 角色ids */
  @JsonIgnore private String roleIdStr;
  /** 角色ID集合 */
  private List<Integer> roleIds;
  /** 逗号分隔的资源ids */
  @JsonIgnore private String resourceIdStr;
  /** 资源ID集合 */
  private List<Integer> resourceIds;

  @Override
  public String getPassword() {
    return password;
  }

  @Override
  public void setPassword(String password) {
    this.password = password;
  }

  @Override
  public String getSalt() {
    return salt;
  }

  @Override
  public void setSalt(String salt) {
    this.salt = salt;
  }

  public String getRoleIdStr() {
    return roleIdStr;
  }

  public void setRoleIdStr(String roleIdStr) {
    this.roleIdStr = roleIdStr;
  }

  public List<Integer> getRoleIds() {
    if (roleIds == null) {
      roleIds = new ArrayList<>();
      for (String id : (null != roleIdStr ? roleIdStr : "").split(",")) {
        if (StringUtils.isEmpty(id)) {
          continue;
        }
        roleIds.add(Integer.valueOf(id));
      }
    }
    return roleIds;
  }

  public void setRoleIds(List<Integer> roleIds) {
    this.roleIds = roleIds;
  }

  public String getResourceIdStr() {
    return resourceIdStr;
  }

  public void setResourceIdStr(String resourceIdStr) {
    this.resourceIdStr = resourceIdStr;
  }

  public List<Integer> getResourceIds() {
    if (resourceIds == null) {
      resourceIds = new ArrayList<>();
      for (String id : (null != resourceIdStr ? resourceIdStr : "").split(",")) {
        if (StringUtils.isEmpty(id)) {
          continue;
        }
        resourceIds.add(Integer.valueOf(id));
      }
    }
    return resourceIds;
  }

  public void setResourceIds(List<Integer> resourceIds) {
    this.resourceIds = resourceIds;
  }
}
